<?php
require_once("../../../util/configuration/configuration_parametters.php");
require_once("../../../util/" . MESSAGES_PROPERTIES . "messages_model.php");
require_once("../../../util/exception/exception_handler.php");

require_once("../../article_category/to/article_category_to.php");
require_once("../../article_category/dao/article_category_dao_factory.php");

require_once("../../autor/to/autor_to.php");
require_once("../../autor/dao/autor_dao_factory.php");

class Article_category_dao_test {

	private $dao;
	private $autor;
	
	public function __construct(){}
	
	public function before_test() {	
		$this->dao = Autor_dao_factory::singleton()->get_dao();
		$this->autor = new Autor_to('xxxxxxxxxxxx','password','email');
		$this->dao->create($this->autor);
		$this->dao = Article_category_dao_factory::singleton()->get_dao();
	}
	
	public function run_test() {
		try {
			$article_category = new Article_category_to(0,'title', 'description', 
														$this->autor->get_login(), 0);
			
			$article_category = (object) $this->dao->create($article_category);		
			echo 'create<br/>';			

			echo 'article: '; 
			echo $article_category->to_string();
			echo '<br/>';
			
			if ($this->dao->exist($article_category->get_number())) {

				$result = $this->dao->fin_by_number_article_category($article_category->get_number());
				echo 'find<br/>';
				
				$aux_article_category = new Article_category_to($result['number'], $result['title'], 
																	$result['description'],	$result['autor_login'],
																	$result['ranking']);

				if ($article_category->equals($aux_article_category)) {
					$article_category->set_description('description2');
					$this->dao->update($article_category);
					echo 'update<br/>';
					
					$result = $this->dao->fin_by_number_article_category($article_category->get_number());
					$aux_article_category = new Article_category_to($result['number'], $result['title'], 
																	$result['description'],	$result['autor_login'],
																	$result['ranking']);
					echo 'article: '; 
					echo $aux_article_category->to_string();
					echo '<br/>';
				}
				
				$this->dao->remove($article_category->get_number());
				echo 'remove<br/>';
				
			}
		}
		catch (Exception $e) {
			Exception_handler::singleton()->handler($e);
		}
	}
	
	public function after_test() {
		Autor_dao_factory::singleton()->get_dao()->remove($this->autor->get_login());
	}
}

//test
$test = new Article_category_dao_test();

$test->before_test();
$test->run_test();
$test->after_test();

?>